package com.project.music.config;

import com.project.music.utils.Consts;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 映射静态资源地址
 */

@Configuration
public class StaticResourceConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //映射图片地址
        registry.addResourceHandler("/img/**").addResourceLocations(
                "file:" + Consts.ROOT + Consts.SEPARATOR + "img" + Consts.SEPARATOR
        );
        //映射歌曲地址
        registry.addResourceHandler("/song/**").addResourceLocations(
                "file:" + Consts.ROOT + Consts.SEPARATOR + "song" + Consts.SEPARATOR
        );
        //映射头像地址
        registry.addResourceHandler("/avatorImages/**").addResourceLocations(
                "file:" + Consts.ROOT + Consts.SEPARATOR + "avatorImages" + Consts.SEPARATOR
        );
    }
}